package com.itheima.快排;

public class MyQuiteDemo2 {
    public static void main(String[] args) {
        int []arr={6,10,3,4,5,1,8};
        method(arr,0,arr.length-1);
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+"    ");
        }

    }
    private static void method(int[]arr,int left,int right){

        int left0=left;
        int right0=right;

        int baseNumber=arr[0];
        while (left!=right){
            //从右边开始找比基准数小的
            while (arr[right]>=baseNumber&&right>left){
                right--;
            }
            //从左边开始往右边找比基准数大的
            while (arr[left]<=baseNumber&&right>left){
                left++;
            }
            //交换两个基准数位置
            int temp=arr[left];
            arr[left]=arr[right];
            arr[right]=temp;
        }
        //基准数归位
        int temp=arr[left];
        arr[left]=arr[left0];
        arr[left0]=temp;


    }

}
